package com.itboye.sunsun.adapter;

import java.util.List;
import com.itboye.sunsunhome.R;
import com.itboye.sunsun.beans.LocationBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SelectAddressAdapter extends BaseAdapter {

	private Context context;
	private List<LocationBean> list;

	public SelectAddressAdapter(Context context, List<LocationBean> list) {
		this.context = context;
		this.list = list;
	}

	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	final class ViewHolder {
		TextView nametext;
		TextView phonetext;
		TextView detailtext;
		TextView uselesstext;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder=null;
		if(convertView==null)
		{
			convertView=LayoutInflater.from(context).inflate(R.layout.location_listview_item,null);
			viewHolder=new ViewHolder();
			
			//注释   by  young
			viewHolder.nametext=(TextView) convertView.findViewById(R.id.nametext);
			viewHolder.phonetext=(TextView) convertView.findViewById(R.id.phonetext);
			viewHolder.detailtext=(TextView) convertView.findViewById(R.id.detailtext);
			viewHolder.uselesstext=(TextView) convertView.findViewById(R.id.useless);
			if(position==0)
			{
				viewHolder.uselesstext.setVisibility(View.VISIBLE);
			}
			
			viewHolder.nametext.setText(list.get(position).getContactname());
			viewHolder.phonetext.setText(list.get(position).getMobile());
			String province=list.get(position).getProvince();
			String city=list.get(position).getCity();
			String area=list.get(position).getArea();
			
			if(city.equals("市辖区")|city.equals("县"))
			{
				city="";
			}
			if(area.equals("市辖区"))
			{
				area="";
			}
			String detail=list.get(position).getDetailinfo();
			viewHolder.detailtext.setText(province+city+area+detail);
			convertView.setTag(viewHolder);
		}else
		{
			viewHolder=(ViewHolder)convertView.getTag();
		}
		
		
		
		return convertView;
	}

}
